import type { AppThunkAction } from '../index'
import { http } from '@/utils'

// 我的页面 - 获取个人信息
const getUserInfo = (): AppThunkAction => {
  return async dispatch => {
    try {
      const res = await http.get('/user')
      const { data, message } = res.data

      if (message.toLowerCase() === 'ok') {
        // 存储 redux 中
        dispatch({ type: 'profile/userInfo', payload: data })
      }
    } catch (e) {}
  }
}

export { getUserInfo }
